package search;

public class InsertSearch {
    public static void main(String[] args) {
        int arr[] = {12, 32, 83, 84, 84, 91, 100, 123, 321};
        System.out.println(search(arr, 0, 8, 83));

    }

    // 返回下标, 闭区间
    private static int search(int arr[], int left, int right, int findVal) {

        System.out.println("hello~");

        // 找不到返回 -1
        if (left > right || findVal < arr[left] || findVal > arr[right]) {
            return -1;
        }

        int mid = left + (right - left) * (findVal - arr[left]) / (arr[right] - arr[left]);
        // 左
        if (findVal < arr[mid]) { //
            return search(arr, left, mid - 1, findVal);
        } else if (findVal > arr[mid]) { //右
            return search(arr, mid + 1, right, findVal);
        } else {
            return mid;
        }
    }


}
